<?php
	session_start();

	require_once("utilities.inc");
		
	echo "SELECT * FROM usuarios where NomUsuario ='".$_POST['login']."' && Clave ='".md5($_POST['password'])."'";

	$resultado = mysqlQuery("SELECT * FROM usuarios where NomUsuario ='".$_POST['login']."'");
	if(mysql_num_rows($resultado) == 1){
		$resultado = mysql_fetch_assoc($resultado);
		if($resultado['Clave'] == md5($_POST['password'])){
		
			if($_POST["remember"]){
				setcookie('user', $_POST["login"], time() + 365 * 24 * 60 * 60, '/PicImg/');
				setcookie('password', md5($_POST["password"]), time() + 365 * 24 * 60 * 60, '/PicImg/');
				
				if(isset($_COOKIE['lastVisit'])){
					$_SESSION['lastVisit'] = $_COOKIE['lastVisit'];
				}else{
					$_SESSION['lastVisit'] = time();
				}
				
				setcookie('lastVisit', time(), time() + 365 * 24 * 60 * 60, '/PicImg/');
			}	
			
			$_SESSION['user'] = $_POST["login"];

			$extra = '../User.php';
		}else{
			$extra = '../index.php';
		}
	}else{
		$extra = '../index.php';
	}
	
	$host = $_SERVER['HTTP_HOST'];
	$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');

	header("Location: http://$host$uri/$extra");
	exit;
?>